<?
	$sess = new Zend_Session_Namespace(CLU_NS);
?>
<style>
a.active
{
	color:blue;
}
a.inactive
{
	color:gray;
}
</style>
<script type="text/javascript">
$(function(){
	contentModule = '<?=$this->viewParams['content_module']?>'
	<?if(isset($this->viewParams['type'])) :?>
		type = '<?=$this->viewParams['type']?>';
	<?else:?>
		type = null;
	<?endif?>
	
	$("a.add").click(function()
		{   
			$.getJSON("/<?=$sess->viewLang?>/admin/ajax/widget-weight",
				{
					content_id: $(this).attr('name'),
					content_title: $(this).attr('title'),
					content_module: contentModule,
					type: type,
					widget_position_id: <?=$this->viewParams['widget_position_id']?>,
					operation: 'insert'
				}, 
                function(json){
                    if(json.success)
                    {
                    	alert('Added');
                    	$(this).addClass('inactive');
                    	$(".remove").attr('name',$(this).attr('name')).addClass('active');
//                    	$(".remove[name=" + $(this).attr('name') + "]").addClass('active');
                    }
                    else
                    	alert(json.errorMessage);
             })
     });
     
     $("a.remove").click(function()
		{   
			$.getJSON("/<?=$sess->viewLang?>/admin/ajax/widget-weight",
				{
					content_id: $(this).attr('name'),
					content_title: $(this).attr('title'),
					content_module: contentModule,
					widget_position_id: <?=$this->viewParams['widget_position_id']?>,
					operation: 'delete'
				}, 
                function(json){
                    if(json.success)
                    	alert('success');
                    else
                    	alert(json.errorMessage);
             })
     });
});
</script>

<div class="box white_bg" style="background-color:#ffffff">

<br/><br/>
<?if(isset($this->viewParams['widgetInfo'])) :?>
<b>You are managing items for widget </b> 
<i>
	<?if (isset($this->viewParams['widgetInfo']['widget_name'])) :?>
	<?=$this->viewParams['widgetInfo']['widget_name'] ?>
	<?else :?>
	<?=$this->viewParams['widgetInfo']['widget_request'] ?>
	<?endif ?>
</i>
	<b> IN </b>  <i><?=$this->viewParams['request'] ?></i>
<br/>
(<span style="color:green">You can remove/add an item to the list</span>)
	
<?endif ?>
<br/>
<hr/>
<br/>
<b> Current items </b>
<br/>
<?if(isset($this->viewParams['currentItems'])) :?>

<?foreach ($this->viewParams['currentItems'] as $k => $v) :?>
	<?=$v['content_id'] ?>
		<a href="javascript:void();" name="<?=$v['content_id']?>" class="add" 
				title="<?=$v['content_title'] ?>"> Add</a>
			 | <a href="javascript:void();" name="<?=$v['content_id']?>" class="remove" 
			 	title="<?=$v['content_title'] ?>" > Remove</a> 
				<?=$v['content_title'];?>
		<br/>
<?endforeach?>
<?endif?>


<br/>
<b> Other featured items that you may wanna add </b> 
<br/>
<?if(isset($this->viewParams['featuredItems'])) :?>

<?foreach ($this->viewParams['featuredItems'] as $k => $v) :?>
<?if (!in_array($v['id'], $this->viewParams['currentItemIds'])) :?>
	<?=$v['id'] ?>
	<?if($this->viewParams['content_module'] == 'place') :?>
		<a href="javascript:void();" name="<?=$v['id']?>" class="add" 
				title="<?=$v['name'] ?>"> Add</a>
			 | <a href="javascript:void();" name="<?=$v['id']?>" class="remove" 
			 	title="<?=$v['name'] ?>" > Remove</a> 
				<?=$v['name'];?>
	<?else: ?>
		<a href="javascript:void();" name="<?=$v['id']?>" class="add" 
				title="<?if(isset($v['title'])):?><?=$v['title'] ?>
						<?else:?>
							<?=$v['name']?>
						<?endif?>
				"> Add</a>
			 | <a href="javascript:void();" name="<?=$v['id']?>" class="remove" 
			 	title="<?if(isset($v['title'])):?><?=$v['title'] ?>
			 			<?else:?>
							<?=$v['name']?>
						<?endif?>
			 	" > Remove</a> 
				<?if(isset($v['title'])):?><?=$v['title'] ?>
	 			<?else:?>
					<?=$v['name']?>
				<?endif?>
	
	<?endif ?>
		<br/>
<?endif ?>
<?endforeach?>
<?endif?>
</div>